<?php

/**
 * descript:
 * User: blue
 * Date: 2018/9/13 11:26
 */

namespace app\library\server;

use app\library\except\ParmasException;
use think\captcha\Captcha;
class ThinkCapture
{
    protected $captcha;
    //验证码配置
    public function __construct(array $config=[])
    {
        $this->captcha=empty($config)?(new Captcha()):(new Captcha($config));
    }

    /**
     * 显示验证码
     * @return \think\Response
     */
    public function showCapture(){

        return $this->captcha->entry();
    }

    /**
     * thinkphp的验证码验证
     * @param $value
     * @return bool
     * @throws ParmasException
     */
    public function checkCapture($value){
        if( !$this->captcha->check($value ))
        {
            throw new ParmasException('验证码错误');
        }
        return true;
    }
}